package cn.itcast.hotel.listen;

import cn.itcast.hotel.service.HotelService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@Slf4j

public class HotelQueueListener {

    @Autowired
    private HotelService hotelService;

    @RabbitListener(bindings = @QueueBinding(
      value =@Queue("hotel.insert.queue"),
            exchange =@Exchange(value = "hotel.topic",type = ExchangeTypes.TOPIC),
            key ="hotel.insert"
    ))
    public void listenInsertQueue(Long hotelId){
        log.info("接收到添加消息");
        hotelService.insertById(hotelId);
    }
    @RabbitListener(bindings = @QueueBinding(
            value =@Queue("hotel.delete.queue"),
            exchange =@Exchange(value = "hotel.topic",type = ExchangeTypes.TOPIC),
            key ="hotel.delete"
    ))
    public void listenDeleteQueue(Long hotelId){
        log.info("接收到删除消息");
        hotelService.deleteById(hotelId);
    }

}
